<?php
/**
 * 	Bushido
 *
 * @category   Bushido
 * @package    Bushido_Controller_Action_Secure
 * @copyright  Copyright (c) 2009 Nathan Keyes
 * @author Nathan Keyes
 * @version    $Id: UserController.php 7 2009-11-07 15:54:13Z nkeyes $
 */
class UserController extends Bushido_Controller_Action_User
{

	// sdffdsgdsg
	/**
	 * (non-PHPdoc)
	 * @see library/Bushido/Controller/Action/Bushido_Controller_Action_User#_authenticate()
	 */
	protected function _authenticate(Zend_Form $loginForm)
	{
		$authResult = $this->_dbPassAuthenticate($loginForm);
		return $authResult;
		
	}
	
	/**
	 * 
	 * @param $loginForm
	 * @return Zend_Auth_Result
	 */
	protected function _dbPassAuthenticate(Zend_Form $loginForm)
	{
		$dbAdapter = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getPluginResource('dbMultiConnection')->getAdapter();
		$authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter, 'bushido_user', 'login', 'password');
		
		$authAdapter->setIdentity($loginForm->getValue('uid'))->setCredential(md5($loginForm->getValue('password')));
		return Zend_Auth::getInstance()->authenticate($authAdapter);
	}
	
	/**
	 * (non-PHPdoc)
	 * @see library/Bushido/Controller/Action/Bushido_Controller_Action_User#_setUserInfo()
	 */
	protected function _setUserInfo($uid)
	{
		parent::_setUserInfo($uid);
		
		
		// execute raw sql to get user id because we need the bushido_user_id in the session for our implementation of Zend_Db_Table/Rowset/Row to work
		Bushido_App::session()->userInfo['bushido_user_id'] = Bushido_Db_Table::getAdapter()->fetchOne("SELECT bushido_user_id FROM bushido_user where login = ?", $uid); 
		//Zend_Debug::dump($uid. '$uid:');
				
		//$user = $userTable->fetchAll($userTable->select()->where('login = ?', $uid))->current();
		$user = Bushido_App::getUser();
		Bushido_App::session()->userInfo['cn'] = Bushido_Db_Table::getDisplayValue($user);
	}
}